package com.lu.dog.dbrowser.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ListView;

import com.lu.adog.adapter.listview.CommonAdapter;
import com.lu.adog.adapter.listview.ViewHolder;
import com.lu.dog.dbrowser.R;
import com.lu.dog.dbrowser.bean.SearchInfo;
import com.lu.dog.dbrowser.db.DBrowserDbHelper;
import com.lu.dog.dbrowser.ui.MainActivity;

import java.util.Date;
import java.util.List;

/**
 * @author Yue
 * @date 2017/12/25 17:23
 */

public class SearchInfoAdapter extends CommonAdapter<SearchInfo> {

    public SearchInfoAdapter(Context context, int layoutId, List<SearchInfo> datas) {
        super(context, layoutId, datas);
    }
    public List<SearchInfo> getDatas(){
        return mDatas;
    }
    @Override
    protected void convert(final ViewHolder viewHolder, final SearchInfo item, final int position) {
        viewHolder.setText(R.id.textView, item.getContent());
        viewHolder.setOnClickListener(R.id.textView, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((MainActivity)mContext).putSearchText(item.getContent());

            }
        });
        viewHolder.setOnClickListener(R.id.imageView, new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                mDatas.remove(position);
                DBrowserDbHelper.getInstance(mContext).deleteSearchInfo(item);
                notifyDataSetChanged();
            }
        });
    }
}
